var app=angular.module("ydApp",["ngRoute","ngAnimate"])
.controller("ydCtrl",["$scope","$http",function($scope,$http){
$scope.page={pageNum:1};
}])
.config(["$routeProvider",function($routeProvider){
$routeProvider
.when("/home",{"templateUrl":"templates/pages/home.html"})
.when("/search",{"templateUrl":"templates/pages/search.html"})
.when("/regist",{"templateUrl":"templates/pages/regist.html"})
.otherwise({"redirectTo":"/home"})
}])
.controller("homeCtrl",["$scope","$http",function($scope,$http){
$scope.page.pageNum=1;

}])
.controller("searchCtrl",["$scope","$http",function($scope,$http){
$scope.page.pageNum=2;

$scope.provinces=null;	// 省份数据
$scope.citys=[];		// 城市数据
$scope.searchInfo={
city_id:'',//城市id
district_id:'',//区域id
start:'',//从第jige
sort:"1",//排序 0/1
start_dates:'',//开始日期
start_time:'',//结束时间
category_id:'',//场馆类型
cbd_id:'',//商圈id
facility_id:'',//条件
keyword:'' // 搜索关键字
};	// 当前查询 场馆的条件
// $.param($scope.searchInfo)
//city_id=320100&district_id=&start=&sort=1&start_dates=&start_time=&category_id=&cbd_id=&facility_id=&keyword=
$scope.searchOptions={};  // 可供选择的条件
$scope.stadiums=[];     // 场馆信息
$scope.currentCity={};
// 第一个大步骤  获取城市列表
$http.get("http://platform-api.1yd.me/api/meta-data/cities")
.success(function(res){
$scope.provinces=res.provinces;
for(var i=0;i<$scope.provinces.length;i++){
// 循环省
for(var j=0; j<$scope.provinces[i].citys.length; j++){
// 循环市
$scope.citys.push($scope.provinces[i].citys[j]);
}
}
$scope.currentCity= $scope.citys[0];
// 默认查询条件的城市 等于城市列表的第0个
getSearchOptions();
// 获取场馆
getStadiums ();

})
// 设置当前城市
$scope.setCurrentCity=function(item){
// 设置当前城市
$scope.currentCity=item;
$scope.searchInfo.city_id=item.city_id;
// 获取展示的 searchOptions 条件
getSearchOptions();
// 获取场馆
getStadiums ();

}

// 获取搜索条件
function getSearchOptions(){
$http.get("http://platform-api.1yd.me/api/meta-data/"+$scope.searchInfo.city_id)
.success(function(res){
$scope.searchOptions=res;
})
}

// 获取场馆
function getStadiums (){
$http.get("http://platform-api.1yd.me/api/stadium_resources?"+$.param($scope.searchInfo))
.success(function(res){
$scope.stadiums=res;
console.log($scope.stadiums);
})

}

// 单击条件  改变 $scope.searchInfo（搜索条件） 执行 getStadiums（）

}])
.controller("registCtrl",["$scope","$http",function($scope,$http){
$scope.page.pageNum=3;
}])

